﻿using Abp.Application.Services.Dto;
using Acme.BookStore.Books;
using Acme.BookStore.Bookss;
using Acme.BookStore.FileImagess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.BookStore
{
    public class ImagesAppService : ApplicationService, IImageAppService
    {
        private readonly IRepository<FileImage, int> _FileImage;

        public ImagesAppService(IRepository<FileImage, int> FileImages)
        {
            _FileImage = FileImages;
        }
        //批量添加图片
        public async Task<int>  CreateImg(CreateUpdateFileImageDto createUpdate)
        {
            List<FileImage> list = new List<FileImage>();
            foreach (var item in createUpdate.IamgeUrl)
            {
                list.Add(new FileImage { IamgeUrl = item, imageCategroy = createUpdate.imageCategroy, imageSId = createUpdate.imageSId });
            }
            await _FileImage.InsertManyAsync(list);
            return 1;
        }
        //删除
        public async Task<int> DeleteImage(List<int> ids)
        {
            foreach (var id in ids)
            {
                await _FileImage.DeleteAsync(id);
            }
            return 1;
        }
        //图片显示
        public PagedResultDto<FileImageDto> GetImage(ImageListDto input)
        {
            var geting = from a in _FileImage
                         select new FileImageDto
                         {
                             Id=a.Id,
                             IamgeUrl = a.IamgeUrl,
                             imageSId = a.imageSId,
                             imageCategroy = a.imageCategroy
                         };
            var list = geting.WhereIf(input.imageSId > 0, s => s.imageSId == input.imageSId).ToList();
            var totalcounnt = list.Count;
            return new Abp.Application.Services.Dto.PagedResultDto<FileImageDto>(totalcounnt, list);
        }
    }
}

